﻿Imports System.Data.SqlClient

Public Class clsIncapacidades
    Private mintidIncapacidad As Integer
    Private mintFolio As Integer
    Private mstrSerie As String
    Private mintIdEmpleado As Integer
    Private mstrNombre As String
    Private mstrIMSS As String
    Private mstrMotivo As String
    Private mstrTipo As String
    Private mdatFechaInicio As Date
    Private mintDias As Integer
    Private mdatFechaFin As Date
    Private mstrDescripcion As String
    Private mstrReportado As String
    Private mstrReportadoT As String
    Public Property idIncapacidad() As Integer
        Get
            Return mintidIncapacidad
        End Get
        Set(ByVal value As Integer)
            mintidIncapacidad = value
        End Set
    End Property
    Public Property Folio() As Integer
        Get
            Return mintFolio
        End Get
        Set(ByVal value As Integer)
            mintFolio = value
        End Set
    End Property
    Public Property Serie() As String
        Get
            Return mstrSerie
        End Get
        Set(ByVal value As String)
            mstrSerie = value
        End Set
    End Property
    Public Property IDEmpleado() As Integer
        Get
            Return mintIdEmpleado
        End Get
        Set(ByVal value As Integer)
            mintIdEmpleado = value
        End Set
    End Property
    Public Property Nombre() As String
        Get
            Return mstrNombre
        End Get
        Set(ByVal value As String)
            mstrNombre = value
        End Set
    End Property
    Public Property IMSS() As String
        Get
            Return mstrIMSS
        End Get
        Set(ByVal value As String)
            mstrIMSS = value
        End Set
    End Property
    Public Property Motivo() As String
        Get
            Return mstrMotivo
        End Get
        Set(ByVal value As String)
            mstrMotivo = value
        End Set
    End Property
    Public Property Tipo() As String
        Get
            Return mstrTipo
        End Get
        Set(ByVal value As String)
            mstrTipo = value
        End Set
    End Property
    Public Property FechaInicio() As Date
        Get
            Return mdatFechaInicio
        End Get
        Set(ByVal value As Date)
            mdatFechaInicio = value
        End Set
    End Property

    Public Property Dias() As Integer
        Get
            Return mintDias
        End Get
        Set(ByVal value As Integer)
            mintDias = value
        End Set
    End Property
    Public Property FechaFin() As Date
        Get
            Return mdatFechaFin
        End Get
        Set(ByVal value As Date)
            mdatFechaFin = value
        End Set
    End Property


    Public Property Descripcion() As String
        Get
            Return mstrDescripcion
        End Get
        Set(ByVal value As String)
            mstrDescripcion = value
        End Set
    End Property
    Public Property Reportado() As String
        Get
            Return mstrReportado
        End Get
        Set(ByVal value As String)
            mstrReportado = value
        End Set
    End Property
    Public Property ReportadoT() As String
        Get
            Return mstrReportadoT
        End Get
        Set(ByVal value As String)
            mstrReportadoT = value
        End Set
    End Property
    Public Sub New()
        mintidIncapacidad = 0
        mintFolio = 0
        mstrSerie = ""
        mintIdEmpleado = 0
        mstrNombre = ""
        mstrIMSS = ""
        mstrMotivo = ""
        mstrTipo = ""
        mdatFechaInicio = Now()
        mdatFechaFin = Now()
        mintDias = 0
        mstrDescripcion = ""
        mstrReportado = ""
        mstrReportadoT = ""

    End Sub
    Public Sub Guardar()

        If idIncapacidad = 0 Then
            Exit Sub
        End If

        Dim intRetVal As Integer

        intRetVal = BuscarIntDatoCitra("Incapacidades", "idincapacidad", "idincapacidad=" & idIncapacidad)

        If intRetVal = 0 Then
            Insertar()
        Else
            Actualizar()
        End If
    End Sub
    Public Sub Borrar()
        Call SetSqlCitra("Delete From Incapacidades Where idIncapacidad = " & idIncapacidad)

    End Sub
    Public Sub Buscar()
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT * From Incapacidades " & _
        " WHERE idIncapacidad=" & idIncapacidad

        Dim rdBuscar As SqlDataReader

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        If rdBuscar.Read() Then
            mintidIncapacidad = rdBuscar("idIncapacidad")
            mintFolio = rdBuscar("folio")
            mstrSerie = rdBuscar("serie").ToString.Trim
            mintIdEmpleado = rdBuscar("idempleado")
            mstrNombre = rdBuscar("nombre").ToString.Trim
            mstrIMSS = rdBuscar("NSS").ToString.Trim
            mstrMotivo = rdBuscar("motivo").ToString.Trim
            mstrTipo = rdBuscar("tipo").ToString.Trim
            mdatFechaInicio = rdBuscar("fechainicio")
            mdatFechaFin = rdBuscar("fechafin")
            mintDias = rdBuscar("dias")
            mstrDescripcion = rdBuscar("descripcion").ToString.Trim
            mstrReportado = rdBuscar("reportado").ToString.Trim
            mstrReportadoT = rdBuscar("reportadot").ToString.Trim
        Else
            mintidIncapacidad = 0
            mintFolio = 0
            mstrSerie = ""
            mintIdEmpleado = 0
            mstrNombre = ""
            mstrIMSS = ""
            mstrMotivo = ""
            mstrTipo = ""
            mdatFechaInicio = Now()
            mdatFechaFin = Now()
            mintDias = 0
            mstrDescripcion = ""
            mstrReportado = ""
            mstrReportadoT = ""
        End If

        rdBuscar.Close()
        cnConn.Close()


    End Sub
    Public Sub Importar()
        Dim sql As String = "Insert Into Incapacidades (" & _
                            "IdIncapacidad," & _
                            "Folio," & _
                            "Serie," & _
                            "IdEmpleado," & _
                            "Nombre," & _
                            "NSS," & _
                            "Motivo," & _
                            "Tipo," & _
                            "FechaInicio," & _
                            "Dias," & _
                            "FechaFin," & _
                            "Descripcion," & _
                            "Reportado," & _
                            "ReportadoT)" & _
                            "VALUES (" & _
                            "@IdIncapacidad," & _
                            "@Folio," & _
                            "@Serie," & _
                            "@IdEmpleado," & _
                            "@Nombre," & _
                            "@NSS," & _
                            "@Motivo," & _
                            "@Tipo," & _
                            "@FechaInicio," & _
                            "@Dias," & _
                            "@FechaFin," & _
                            "@Descripcion," & _
                            "@Reportado," & _
                            "@ReportadoT)"


        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdIncapacidad", mintidIncapacidad)
        Command.Parameters.AddWithValue("Folio", mintFolio)
        Command.Parameters.AddWithValue("Serie", mstrSerie)
        Command.Parameters.AddWithValue("IdEmpleado", mintIdEmpleado)
        Command.Parameters.AddWithValue("Nombre", mstrNombre)
        Command.Parameters.AddWithValue("NSS", mstrIMSS)
        Command.Parameters.AddWithValue("Motivo", mstrMotivo)
        Command.Parameters.AddWithValue("Tipo", mstrTipo)
        Command.Parameters.AddWithValue("FechaInicio", mdatFechaInicio)
        Command.Parameters.AddWithValue("Dias", mintDias)
        Command.Parameters.AddWithValue("FechaFin", mdatFechaFin)
        Command.Parameters.AddWithValue("Descripcion", mstrDescripcion)
        Command.Parameters.AddWithValue("Reportado", mstrReportado)
        Command.Parameters.AddWithValue("ReportadoT", mstrReportadoT)

        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar la Liquidacion ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into Incapacidades (" & _
                            "IdIncapacidad," & _
                            "Folio," & _
                            "Serie," & _
                            "IdEmpleado," & _
                            "Nombre," & _
                            "NSS," & _
                            "Motivo," & _
                            "Tipo," & _
                            "FechaInicio," & _
                            "Dias," & _
                            "FechaFin," & _
                            "Descripcion," & _
                            "Reportado," & _
                            "ReportadoT)" & _
                            "VALUES (" & _
                            "@IdIncapacidad," & _
                            "@Folio," & _
                            "@Serie," & _
                            "@IdEmpleado," & _
                            "@Nombre," & _
                            "@NSS," & _
                            "@Motivo," & _
                            "@Tipo," & _
                            "@FechaInicio," & _
                            "@Dias," & _
                            "@FechaFin," & _
                            "@Descripcion," & _
                            "@Reportado," & _
                            "@ReportadoT)


        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdIncapacidad", mintidIncapacidad)
        Command.Parameters.AddWithValue("Folio", mintFolio)
        Command.Parameters.AddWithValue("Serie", mstrSerie)
        Command.Parameters.AddWithValue("IdEmpleado", mintIdEmpleado)
        Command.Parameters.AddWithValue("Nombre", mstrNombre)
        Command.Parameters.AddWithValue("NSS", mstrIMSS)
        Command.Parameters.AddWithValue("Motivo", mstrMotivo)
        Command.Parameters.AddWithValue("Tipo", mstrTipo)
        Command.Parameters.AddWithValue("FechaInicio", mdatFechaInicio)
        Command.Parameters.AddWithValue("Dias", mintDias)
        Command.Parameters.AddWithValue("FechaFin", mdatFechaFin)
        Command.Parameters.AddWithValue("Descripcion", mstrDescripcion)
        Command.Parameters.AddWithValue("Reportado", mstrReportado)
        Command.Parameters.AddWithValue("ReportadoT", "Inicial")

        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar la Liquidacion ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
    Public Sub Actualizar()

        Dim strSqlQry As String
        Dim cnConn As New SqlConnection

        cnConn.ConnectionString = CitraConnection
        strSqlQry = "Update Incapacidades Set " & _
                            "Folio=@Folio," & _
                            "Serie=@Serie," & _
                            "IdEmpleado=@IdEmpleado," & _
                            "Nombre=@Nombre," & _
                            "NSS=@NSS," & _
                            "Motivo=@Motivo," & _
                            "Tipo=@Tipo," & _
                            "FechaInicio=@FechaInicio," & _
                            "Dias=@Dias," & _
                            "FechaFin=@FechaFin," & _
                            "Descripcion=@Descripcion," & _
                            "Reportado=@Reportado," & _
                            "ReportadoT=@ReportadoT " & _
                            "Where IdIncapacidad=@IdIncapacidad"


        Dim Command As New SqlCommand(strSqlQry, cnConn)

         Command.Parameters.AddWithValue("IdIncapacidad", mintidIncapacidad)
        Command.Parameters.AddWithValue("Folio", mintFolio)
        Command.Parameters.AddWithValue("Serie", mstrSerie)
        Command.Parameters.AddWithValue("IdEmpleado", mintIdEmpleado)
        Command.Parameters.AddWithValue("Nombre", mstrNombre)
        Command.Parameters.AddWithValue("NSS", mstrIMSS)
        Command.Parameters.AddWithValue("Motivo", mstrMotivo)
        Command.Parameters.AddWithValue("Tipo", mstrTipo)
        Command.Parameters.AddWithValue("FechaInicio", mdatFechaInicio)
        Command.Parameters.AddWithValue("Dias", mintDias)
        Command.Parameters.AddWithValue("FechaFin", mdatFechaFin)
        Command.Parameters.AddWithValue("Descripcion", mstrDescripcion)
        Command.Parameters.AddWithValue("Reportado", mstrReportado)
        Command.Parameters.AddWithValue("ReportadoT", "Correccion")
        cnConn.Open()

        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible actualizar el liquidación ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If



    End Sub


End Class
